import logging
from PySide6.QtWidgets import QMainWindow
from docu_kit.ui.window_main_ui import Ui_MainWindow
from docu_kit.windows import window_01, window_02, window_03


class MainWindow(QMainWindow):
    """自定义Qt主窗口"""

    def __init__(self):
        """初始化"""
        QMainWindow.__init__(self)
        # 设置日志
        self.logger = logging.getLogger("qt")  # 创建日志
        self.logger.setLevel(logging.DEBUG)  # 设置日志等级
        formatter = logging.Formatter("%(asctime)s - %(levelname)s: %(message)s")  # 设置日志格式
        # 添加控制台处理器
        console_handler = logging.StreamHandler()
        console_handler.setLevel(logging.DEBUG)
        console_handler.setFormatter(formatter)
        self.logger.addHandler(console_handler)
        # 初始化界面
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.show_window = self.ui.window_00
        self.ui.window00Button.clicked.connect(lambda: self.switch_window(self.ui.window_00))
        self.window_01 = window_01.Window(self.logger)
        self.window_01.hide()
        self.ui.centralwidget.layout().addWidget(self.window_01)
        self.ui.window01Button.clicked.connect(lambda: self.switch_window(self.window_01))
        self.window_02 = window_02.Window(self.logger)
        self.window_02.hide()
        self.ui.centralwidget.layout().addWidget(self.window_02)
        self.ui.window02Button.clicked.connect(lambda: self.switch_window(self.window_02))
        self.window_03 = window_03.Window(self.logger)
        self.window_03.hide()
        self.ui.centralwidget.layout().addWidget(self.window_03)
        self.ui.window03Button.clicked.connect(lambda: self.switch_window(self.window_03))

    def switch_window(self, window):
        self.show_window.hide()
        window.show()
        self.show_window = window
